{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>酒店添加</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" name="add_article" id="add_article" enctype="multipart/form-data">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="input-group col-sm-4">
                                <input id="h_name" name="h_name" type="text" class="form-control h_name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">图片：</label>
                            <div class="input-group col-sm-5">
                                <input type="hidden" id="data_photo" name="images" >
                                <div id="imgPicker" style="float:left">选择图片</div>
                                <img id="img_data" height="100px" style="float:left;margin-left: 50px;margin-top: -10px;cursor:pointer;" src="/static/admin/images/no_img.jpg" onclick='imgDisplay(this)'/>
                                <div id="fileList" class="uploader-list" style="float:right"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label cyanse">酒店分类</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b" name="h_cate" id="h_cate">
                                    <option value="1">国内</option>
                                    <option value="2">国外</option>
                                    <option value="2">钟点</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label cyanse">酒店星级</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b" name="h_level" id="h_level">
                                    <option value="1">一星</option>
                                    <option value="2">二星</option>
                                    <option value="3">三星</option>
                                    <option value="4">四星</option>
                                    <option value="5">五星</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">定位地址：</label>
                            <div class="input-group col-sm-11">
                                <!--此处一定要注意百度地图不兼容的问题-->
                                <div id='map_canvas' style='margin-left:160px;width:90%;height:400px;z-index: 100;'>
                                </div>
                                <div id="r-result" style="margin-left: 150px;margin-top:10px">请输入:
                                    <input title="定位地址(请输入)" class="h_address"  name="h_address" type="text" id="suggestId" size="20" style="width:400px;height:30px"/>
                                </div>
                                <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;">

                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">定位经纬度：</label>
                            <div class="input-group col-sm-4">
                                <table>
                                    <tr>
                                        <td>
                                            <input type="text"  name="longitude" style="margin-left: 20px;height:30px" placeholder="输入经度" />
                                        </td>
                                        <td>
                                            <input type="text"   name="latitude" style="margin-left: 20px;height:30px" placeholder="输入纬度" />
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label cyanse">酒店类型</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b" name="h_type" id="h_type">
                                    {volist name="data" id="vo"}
                                    <option value="{$vo.type_id}">{$vo.type_name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">有无无线网</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b" name="h_wifi" id="h_wifi">
                                    <option value="1">有</option>
                                    <option value="2">无</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">有无有线网</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b" name="h_wried" id="h_wried">
                                    <option value="1">有</option>
                                    <option value="2">无</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">有无停车场</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b" name="h_p" id="h_p">
                                    <option value="1">有</option>
                                    <option value="2">无</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="Member" style="display:none">
                            <label class="col-sm-3 control-label">酒店电话</label>
                            <div class="input-group col-sm-4">
                                <input type="text"  name="h_phone"  class="form-control layer-date search h_phone" placeholder="酒店电话"
                                       onkeyup="this.value=this.value.replace(/\D/gi,'')"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">最低价格：</label>
                            <div class="input-group col-sm-4">
                                <input id="" type="text" name="h_min_price" class="form-control activity_time">
                            </div>
                        </div>

                        <!--<div class="form-group" id="MyContent">-->
                            <!--<label class="col-sm-3 control-label cyanse" for="myEditor">内容：</label>-->
                            <!--<div class="input-group col-sm-9">-->
                                <!--<textarea   class="content" name="activity_content"style="width:90%" id="myEditor">-->
                                <!--</textarea>-->
                                <!--<a id="myEditors" style="color:#A94543"></a>-->
                            <!--</div>-->
                        <!--</div>-->


                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary btsave"  type="button"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    wk.upload("{:url('Upload/upload')}",2);
</script>
<script>
    $(function(){
        $("#container").show();
        $(":input[name='longitude'],:input[name='latitude']").click(function(){
            alert('拖动坐标点设置订单用餐地址的经纬度！');
        });
        //创建一个地图实例，参数可以是元素id也可以是元素对象，其中BMap是百度地图API里面的命名空间
        var map=new BMap.Map("map_canvas");
        var point=new BMap.Point(118.835399,31.873649);//创建一个坐标点，其中116表示经度，39表示纬度
//创建地图实例后，必须对其进行初始化，初始化后才能进行其它的操作，该方法设置中心点坐标和地图级别
        map = setMap(map,point);
        /**
         *执行智能搜索的功能
         **/
        var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
                {"input" : "suggestId"
                    ,"location" : map
                });

        ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
            var str = "";
            var _value = e.fromitem.value;
            var value = "";
            if (e.fromitem.index > -1) {
                value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            }
            str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

            value = "";
            if (e.toitem.index > -1) {
                _value = e.toitem.value;
                value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            }
            str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
            G("searchResultPanel").innerHTML = str;
        });

        var myValue;
        ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
            var _value = e.item.value;
            myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

            setPlace();
        });

        function setPlace(){
            map.clearOverlays();    //清除地图上所有覆盖物
            function myFun(){
                var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
                var longitude=document.getElementsByName("longitude");
                var latitude=document.getElementsByName("latitude");
                longitude[0].value= pp.lng;
                latitude[0].value= pp.lat;
                map = setMap(map,pp);
            }
            var local = new BMap.LocalSearch(map, { //智能搜索
                onSearchComplete: myFun
            });
            local.search(myValue);
        }
        function G(id) {
            return document.getElementById(id);
        }
//对地图信息进行基础的配置
        function setMap(map,myPoint){
            map.centerAndZoom(myPoint, 18);
            //启用轮滚进行放大缩小，默认为禁用
            map.enableScrollWheelZoom();
//向地图添加控件
            map.addControl(new BMap.NavigationControl());//平移缩放控件，默认在地图左上方
//            map.addControl(new BMap.ScaleControl());//比例尺控件，默认在地图左下方
            map.addControl(new BMap.OverviewMapControl());//缩略图控件，默认在地图右下方

//控制控件的位置,anchor:表示停靠在地图的哪个脚，offset指定偏移量，离地图边界相隔多少像素
            var marker=new BMap.Marker(myPoint); //创建标注
            map.addOverlay(marker);//将标注添加到地图中
            marker.enableDragging();//表示标注可拖拽，默认不可
// 监听标注点击事件
            marker.addEventListener("click",function(){
                alert("请拖动标注获得地址经纬度");
            });
//监听标注拖拽位置事件
            marker.addEventListener("dragend",function(e){
                var longitude=document.getElementsByName("longitude");
                var latitude=document.getElementsByName("latitude");
                longitude[0].value= e.point.lng;
                latitude[0].value= e.point.lat;
            });
            return map;
        }
    });
</script>
<script type="text/javascript">
    //百度富文本编辑器
    var editor = UE.getEditor('myEditor', {
        initialFrameHeight:450,
        autoHeight: false,
        autoHeightEnabled:false,
        autoFloatEnabled:false
    });
</script>
<script>
    $(".btsave").on('click',function () {
        $('.btn').attr('disabled',true);
        var h_name = $(".h_name").val();
        if(h_name==''){
            layer.msg("酒店名称不能为空", {icon: 1, time: 1500, shade: 0.1}, function (index) {
            });
            $('.btn').removeAttr('disabled');
            return false;
        }
        $.ajax({
            url: "{:url('add')}",
            type: "post",
            dataType:'json',
            data: $("#add_article").serialize(),
            success: function (data) {
                if (data.code == 200) {
                    wk.success(data.msg,"{:url('hotel/index')}",1);
                } else if(data.code == 100){
                    $('.btn').removeAttr('disabled');
                    wk.error(data.msg,'',2);
                    return false;
                }
            }
        });
    })
</script>
</body>
</html>